import { defineStore } from "pinia";

export const useStore = defineStore('store', {
    persist: {
        enabled: true,
        strategies: [
            {
                // 缓存的模块名称
                key: "store",
                // 保存位置，默认保存在sessionStorage
                storage: localStorage,
                // 缓存哪些状态
                paths: ["username"]
            }
        ]
    },
    getters:{
        isLogin(state){
            return !!state.token;
        }
    },
    state: () => {
        return {
            token: '',
            username: '',
            type: '',//管理员状态
            routes:[]//路由表
        }
    },
    actions: {
        changeUsername(payload) {
            this.username = payload;
        }
    }
});
